﻿using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;

namespace LKCMS.Web
{
    public partial class Photo : System.Web.UI.Page
    {
        public int Id;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (!int.TryParse(Request.Params["id"] as string, out this.Id))
                {
                    JscriptMsg(300, 120, "错误提示", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:24px;\"><b>亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">您要打开的信息不存在或参数不正确。<span/><br/></div><div style=\"text-align:center;\"><a href=\"Index.aspx\">跳转到首页</a></div>");
                    return;
                }
                else
                {
                    Bind(this.Id);

                }
            }
        }
        private void BindMeta(string classname)
        {
            LKCMS.Model.WebSet webset = new LKCMS.BLL.WebSet().loadConfig(LKCMS.Common.Utils.GetXmlMapPath("Configpath"));

            Page.Title = classname + "_" + webset.WebKeywords;


            //Encode/Content type
            HtmlMeta encode = new HtmlMeta();
            encode.HttpEquiv = "Content-Type";
            encode.Content = "text/html; charset=utf-8";
            Page.Header.Controls.Add(encode);

            //Language
            HtmlMeta lang = new HtmlMeta();
            lang.HttpEquiv = "Content-Language";
            lang.Content = "zh-cn";
            Page.Header.Controls.Add(lang);

            //Description
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = webset.WebDescription;
            Page.Header.Controls.Add(desc);

            //Keyword
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = webset.WebKeywords;
            Page.Header.Controls.Add(keywords);

        }
        /// <summary>
        /// 遮罩提示窗口
        /// </summary>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="msgtitle">窗口标题</param>
        /// <param name="msgbox">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        private void JscriptMsg(int w, int h, string msgtitle, string msgbox)
        {
            string msbox = "";
            msbox += "<script src=\"Js/jsmsg.js\" type=\"text/javascript\"></script>\n";
            msbox += "<script type=\"text/javascript\">\n";

            msbox += "alertWin('" + msgtitle + "','" + msgbox + "'," + w + "," + h + ");";
            msbox += "</script>";
            this.Literal2.Text = msbox;
            //  Msg.Text = msbox;
            // Response.End();
        }
        private void Bind(int id)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.BLL.Article all = new LKCMS.BLL.Article();
            LKCMS.Model.Channel model = bll.GetModel(id);

            string typename = model.Title;
            BindMeta(typename);
            DataTable dt = bll.GetListNew(" ParentId=" + id);

            if (dt.Rows.Count > 0)
            {
                
                sb.Append("<div class=\"type_menu_dao\">");
                sb.Append("<div style=\"background:url(images/daohang.jpg) no-repeat; width:280px; height:30px; margin-left:3px; line-height:30px; text-align:center; color:#FBF204; font-size:14px;\">");
                sb.Append("<b>" + typename + "</b></div>");
                sb.Append("<ul>");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append(" <li><a title=\"" + dr["Title"].ToString() + "\" href=\"NormalType.aspx?id=" + dr["ID"].ToString() + "\"><b>" + dr["PageUrl"].ToString() + "</b></a></li>");

                   // sb1.Append(GetData(int.Parse(dr["ID"].ToString())));
                    //sb1.Append("<div class=\"index_sort_border\">");
                    //sb1.Append("<div class=\"title_block\" >● <a href=\"NormalType.aspx?id=" + dr["ID"].ToString() + "\">" + dr["PageUrl"].ToString() + " <strong>... 查看更多</a></strong></div>");
                    //sb1.Append(GetData(bll.GetModel(int.Parse(dr["ID"].ToString()))));
                    //sb1.Append("<div style=\"clear:both\"></div>");
                    //sb1.Append("<div class=\"title_block_bg_bottom\"></div>");
                    //sb1.Append("</div>");
                }
                sb.Append("   </ul>");
                sb.Append("</div>");
            }




            //最近更新
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>最近更新</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            string s = bll.GetChannels(id).ToString();
            if (s != "")
            {
                DataTable dtzj = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                foreach (DataRow dr1 in dtzj.Rows)
                {
                    sb.Append("<li>. <a href=\"/DetailTW.aspx?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + dr1["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");

            //最热
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>热点</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            s = bll.GetChannels(id).ToString();
            if (s != "")
            {
                DataTable dtzr = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                foreach (DataRow dr2 in dtzr.Rows)
                {
                    sb.Append("<li>. <a href=\"/DetailTW.aspx?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + dr2["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");
            this.LiteraClassType.Text = sb.ToString();
            

            DataTable dpic = bll.GetListNew("PageUrl like '%风光图片%'");
            foreach (DataRow drp in dpic.Rows)
            {
                sb1.Append(GetData(int.Parse(drp["ID"].ToString())));
            }
            this.LiteralContent.Text = sb1.ToString();
            this.LiteralTitle.Text = typename;


        }
        private StringBuilder GetData(int classid)
        {
            LKCMS.BLL.Article pll = new LKCMS.BLL.Article();
            StringBuilder sb1 = new StringBuilder();
            LKCMS.BLL.Channel cll = new LKCMS.BLL.Channel();
            LKCMS.Model.Channel model = cll.GetModel(classid);
            if (model != null)
            {
                DataTable dt = pll.GetList(5, "ClassId=" + classid, "AddTime desc").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    int m = 5 - dt.Rows.Count;
                    sb1.Append(" <div id=\"p_sma\"><a href=\"SmallType.aspx?id="+model.Id+"\">" + model.Title + " - " + model.PageUrl + "</a></div>");
                    sb1.Append("<table width=\"100%\" class=\"white01\">");
                    sb1.Append("<tr>");
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {

                        sb1.Append("<td width=\"20%\">");
                        sb1.Append("<div id=\"p_bg\">");
                        sb1.Append("<a href=\"DetailWB.aspx?id=" + dt.Rows[i]["ID"].ToString() + "\" title=\"" + dt.Rows[i]["Title"].ToString() + "\" target=\"_blank\">");
                        sb1.Append("<img src=\"" + dt.Rows[i]["ImgUrl"].ToString() + "\" style=\"border:solid 1px #ccc;  width:112px; height:82px;\"></a></div>");
                        sb1.Append("<div id=\"p_text\">. <a href=\"" + dt.Rows[i]["ImgUrl"].ToString() + "\" target=\"_blank\">" + dt.Rows[i]["Title"].ToString() + "</a></div>");
                        sb1.Append("</td>");



                    }
                    if (m != 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {

                            sb1.Append("<td width=\"20%\">");
                            sb1.Append("</td>");


                        }


                    }
                    sb1.Append("</tr>");
                    sb1.Append("</table>");

                }

            }


            return sb1;
        }
    }
}
